//
//  xing.m
//  五角星
//
//  Created by situ_ios_004 on 15/9/24.
//  Copyright (c) 2015年 situ_ios_004. All rights reserved.
//

#import "xing.h"

@implementation xing


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self drawEllipse:context];
    [self drawStar:context];
    
    [self drawText:context];
    
}

-(void) drawStar:(CGContextRef) context{
    [[UIColor redColor] set];
    
    //确定中心点
    CGPoint centerPoint=CGPointMake(160, 230);
    //确定半径
    CGFloat radius=70.0;
    //五角星到顶点
    CGPoint p1=CGPointMake(centerPoint.x, centerPoint.y-radius);
    CGContextMoveToPoint(context, p1.x, p1.y);
    //五角星每个点之间点夹角，采用弧度计算。没两个点进行连线就可以画出五角星
    //点与点之间点夹角为2*M_PI/5.0，
    CGFloat angle=4*M_PI/5.0;
    for (int i=1; i<=5; i++) {
        CGFloat x=centerPoint.x-sinf(i*angle)*radius;
        CGFloat y=centerPoint.y-cosf(i*angle)*radius;
        CGContextAddLineToPoint(context, x, y);
    }
    CGContextDrawPath(context, kCGPathFillStroke);
}

-(void)drawText:(CGContextRef)context{
    

//    //绘制到指定的区域内容
//    NSArray* aa=[NSArray arrayWithObjects:@"今",@"天",@"星",@"期",@"几",@"啊",nil];
//    
//    //确定中心点
//    CGPoint centerPoint=CGPointMake(160, 230);
//    //确定半径
//    CGFloat radius=110.0;
//    //五角星到顶点
//    CGPoint p1=CGPointMake(centerPoint.x, centerPoint.y-radius);
//    CGContextMoveToPoint(context, p1.x, p1.y);
//    //五角星每个点之间点夹角，采用弧度计算。没两个点进行连线就可以画出五角星
//    //点与点之间点夹角为2*M_PI/5.0，
//    CGFloat angle=2*M_PI/6.0;
//    for (int i=0; i<=5; i++) {
//        CGFloat x=centerPoint.x-sinf(i*angle)*radius;
//        CGFloat y=centerPoint.y-cosf(i*angle)*radius;
//        CGRect rect= CGRectMake(x, y, 280, 300);
//        UIFont *font=[UIFont systemFontOfSize:20];//设置字体
//        UIColor *color=[UIColor blueColor];//字体颜色
//        NSMutableParagraphStyle *style=[[NSMutableParagraphStyle alloc]init];//段落样式
//        NSTextAlignment align= NSTextAlignmentJustified;//对齐方式
//        style.alignment=align;
//       
//        NSString *bb=[aa objectAtIndex:i];
//        [bb  drawInRect:rect withAttributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:color,NSParagraphStyleAttributeName:style}];
//        
//    }
//    CGContextDrawPath(context, kCGPathFillStroke);
    
}
#pragma mark 绘制椭圆
-(void)drawEllipse:(CGContextRef)context{
    

    //添加对象,绘制椭圆（圆形）的过程也是先创建一个矩形
    CGRect rect=CGRectMake(35, 120, 270.0, 240.0);
    
    CGContextAddEllipseInRect(context, rect);
    //设置属性
    [[UIColor redColor]setStroke];//设置红色边框

    //绘制
    //CGContextDrawPath(context, kCGPathFillStroke);
    CGContextDrawPath(context, kCGPathStroke);
    
}
@end
